package com.izhang3.proxy.controller;

import com.izhang3.proxy.channel.ChannelService;
import com.izhang3.proxy.check.IpCheckService;
import com.izhang3.proxy.client.CrawlClientService;
import com.izhang3.proxy.config.ChannelTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张良
 * @desc
 * @since 2019/6/20 13:47
 */
@RestController
@RequestMapping("/api/v1/ip/")
public class GetIpProxyController {

    @Autowired
    private ChannelService channelService;

    @Autowired
    private CrawlClientService crawlClientService;

    @Autowired
    private IpCheckService ipCheckService;

    @GetMapping("/get")
    public String ip() {
        return channelService.getIp();
    }

    /**
     * 重新加载一批代理IP
     *
     * @return
     */
    @GetMapping("/pull")
    public String reload() {
        crawlClientService.pull();
        return "success";
    }

    @GetMapping("/check")
    public String check() {
        ipCheckService.check(ChannelTypeEnum.WAITING);
        return "success";
    }
}
